package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "店鋪相關接口")
@RequestMapping("/admin/shop")
@RestController
public class ShopController {

    @Autowired
    private RedisTemplate redisTemplate;

    public static final String KEY = "SHOP_STATUS";

    @ApiOperation("修改店鋪狀態相關接口")
    /**
     * 修改店鋪狀態
     * @return
     */
    @PutMapping("/{status}")
    public Result update(@PathVariable Integer status) {
        log.info("店鋪狀態：{}", status == 1 ? "正營業": "已打樣");

//        將營業狀態加進redis數據庫
        redisTemplate.opsForValue().set(KEY, status);

        return  Result.success();
    }


    @ApiOperation("查詢店鋪狀態相關接口")
    /**
     * 查詢店鋪狀態
     * @return
     */
    @GetMapping("/status")
    public Result<Integer> select() {
        Integer status = (Integer)redisTemplate.opsForValue().get(KEY);

        log.info("獲得店鋪狀態為：{}", status == 1 ? "正營業": "已打樣");
        return  Result.success(status);
    }

}
